package com.etc.controller;

import com.etc.entity.Area;
import com.etc.service.AreaService;
import com.etc.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("areaapi")
public class AreaController {

    @Autowired
    AreaService areaService;

    @RequestMapping(value = "listAreaByPage", method = RequestMethod.GET)
    @ResponseBody
    public PageData<Area> selectAreaByPage(@RequestParam(name="content",required=false,defaultValue="")String content, @RequestParam(name="page",required=false,defaultValue="1") Integer page, @RequestParam(name="pageSize",required=false,defaultValue="999") Integer pageSize) {
        PageData<Area> pd = areaService.selectAreaByPage(page, pageSize, content);
        pd.setCode(0);
        pd.setMsg("请求成功");
        return pd;
    }
    @RequestMapping(value = "listProvince", method = RequestMethod.GET)
    @ResponseBody
    public List<Area> selectProvince(){
        List<Area> list=areaService.selectProvince();
        return list;
    }

    @RequestMapping(value = "listCity/{provinceId}", method = RequestMethod.GET)
    @ResponseBody
    public List<Area> selectCity(@PathVariable(value = "provinceId") Integer provinceId){
        List<Area> list=areaService.selectCity(provinceId);
        return list;
    }

    @RequestMapping(value = "recommend", method = RequestMethod.GET)
    public String toRecommend() {
        return "recommend";
    }
 }
